﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SqlToStringBuilder
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnFormat_Click(object sender, EventArgs e)
        {
            txtFormatted.Clear();
            
            foreach (string Line in txtSource.Lines)
            {
                string temp = Line;
                char tabs = '\u0009';

                temp = temp.Replace(tabs.ToString(), @"\t");
                temp = txtVariableName.Text + ".AppendLine(\"" + temp + "\");";
                
                if (temp.Length > 0)
                    txtFormatted.AppendText(temp + "\r\n");
            }
            
        }

        

        private void btnFormatSQL_Click(object sender, EventArgs e)
        {
            txtSource.Clear();

            foreach (string Line in txtFormatted.Lines)
            {
                string temp = Line;
                
                temp = temp.Replace(@"\t","\t");
                temp = temp.Replace(txtVariableName.Text + ".AppendLine(\"", "");
                temp = temp.Replace("\");", "");
                
                if(temp.Length > 0)
                    txtSource.AppendText(temp + "\r\n");
            }
        }

        private void btnCopyToClipboard_Click(object sender, EventArgs e)
        {

            System.Windows.Forms.Clipboard.SetText(txtSource.Text);
        }

        private void btnCopyCSharp_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.Clipboard.SetText(txtFormatted.Text);
        }
    }
}
